import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

const routes = [
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('../views/Login')
    },
    {
        path: '/home',
        name: 'Home',
        component: () => import('../views/Home')
    },
    {
        path: '/mine',
        name: 'Mine',
        component: () => import('../views/Mine')
    },
    {
        path:'/edit',
        name:'Edit',
        component:() => import('../views/MineEdit')
    },
    {
        path:'/university',
        name:'University',
        component:() => import('../views/University')
    },
    {
        path:'/uniList',
        name:'UniList',
        component:() => import('../views/UniversityList')
    },
    {
        path:'/uniDetail/:status/:uniId/:uniName',
        name:'UniDetail',
        component:() => import('../views/UniversityDetail'),
        props($route){
            return {
                uniId:$route.params.uniId,
                status:$route.params.status,
                uniName:$route.params.uniName
            }
        }
    },
    {
        path:'/major',
        name:'Major',
        component:() => import('../views/Major')
    },
    {
        path:'/mbti',
        name:'Mbti',
        component:() => import('../views/Mbti'),
        children:[
            {path:'question',name:'Question',component:() => import('../views/MbtiQuestion')}
        ]
    },
    {
        path:'/recMajor',
        name:'RecMajor',
        component: () => import('../views/RecMajor')
    },
    {
        path:'/recUniversity/:userId/:majorId',
        name:'RecUniversity',
        component: () => import('../views/RecUniversity')
    },
    {
        path:'/openUniversity/:cateFlag/:majorId',
        name:'OpenUniversity',
        props($route){
            return {
                cateFlag:$route.params.cateFlag,
                majorId:$route.params.majorId
            }
        },
        component: () => import('../views/OpenUniversity')
    },
    {
        path:'/UniversityOfficial/:name/:off',
        name:'UniversityOfficial',
        props($route){
            return {
                name:$route.params.name,
                off:$route.params.off
            }
        },
        component: () => import('../views/UniversityOfficial')
    },
    {
        path:'/UniversityAdmission/:name/:adm',
        name:'UniversityAdmission',
        props($route){
            return {
                name:$route.params.name,
                adm:$route.params.adm
            }
        },
        component: () => import('../views/UniversityAdmission')
    },
    {
        path: '/signup',
        name: 'Signup',
        component: () => import('../views/Signup')
    }
]

const router = new VueRouter({
    routes
})

export default router
